<?php
namespace app\common\service\ability\service;
use app\common\service\ability\interfaces\DictionaryValueAbility;
use app\common\exception\TokenException;
use app\common\exception\LogicException;
use app\common\model\DictionaryValue;
use think\db\exception\DataNotFoundException;
//字典值能力类
class DictionaryValueAbilityService implements DictionaryValueAbility{
    public function __construct(DictionaryValue $dictionaryValue)
    {
        $this->models = $dictionaryValue;
    }
    //获取字典值列表带分页
    public function getListPage($where){
        $page = getPageData();
        $orderStr = getOrderString();
        return $this->models->where($where)->limit($page['start'], $page['limit'])->order($orderStr.'value_id desc')->select();
    }
    public function getCount($where){
        return $this->models->where($where)->count();
    }
    //保存字典值添加
    public function saveAdd($addData){
        return $this->models->create($addData);
    }
    //获取字典值信息
    public function getLine($where){
        return $this->models->where($where)->find();
    }
    public function saveEdit($editData){
        $where[]=['value_id','=',$editData['value_id']];
        return  $this->getLine($where)->save($editData);
    }
    public function saveDel($delData){
        $where[]=['value_id','=',$delData['value_id']];
        return  $this->getLine($where)->delete();
    }
    //根据字典id获取字典值选项
    public function getDictionaryValue($dictionaryId){
        $where[] = ['dictionary_id', '=', $dictionaryId];
        $valueArr = $this->models->field('label,value')->where($where)->order('sort desc,dictionary_id asc')->select();
        if($valueArr->isEmpty()){
            return   [];
        }else{
            return   $valueArr;
        }
   
    }
}